<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="指标名称" prop="dictName">
        <el-input
          v-model="queryParams.dictName"
          placeholder="请输入指标名称"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="备注" prop="dictType">-->
<!--        <el-input-->
<!--          v-model="queryParams.dictType"-->
<!--          placeholder="请输入备注"-->
<!--          clearable-->
<!--          style="width: 240px"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="状态" prop="status">-->
<!--        <el-select-->
<!--          v-model="queryParams.status"-->
<!--          placeholder="状态"-->
<!--          clearable-->
<!--          style="width: 240px"-->
<!--        >-->
<!--          <el-option-->
<!--            v-for="item in statusOptions"-->
<!--            :key="item.value"-->
<!--            :label="item.label"-->
<!--            :value="item.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="创建时间">-->
<!--        <el-date-picker-->
<!--          v-model="dateRange"-->
<!--          style="width: 240px"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          type="daterange"-->
<!--          range-separator="-"-->
<!--          start-placeholder="开始日期"-->
<!--          end-placeholder="结束日期"-->
<!--        ></el-date-picker>-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:dict:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:dict:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:dict:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:dict:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="handleRefreshCache"
          v-hasPermi="['system:dict:remove']"
        >刷新缓存</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="dataList2" @selection-change="handleSelectionChange" row-key="dictName">
<!--    <el-table-column label="编号" align="center" prop="id" />-->
    <el-table-column label="指标名称" align="center" prop="dictName" :show-overflow-tooltip="true" />
    <el-table-column label="值" align="center" prop="value":show-overflow-tooltip="true"></el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:dict:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:dict:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="handlePath(scope.row)"
            v-hasPermi="['system:dict:view']"
          >跟踪</el-button>
          <!--            <router-link :to="'/datamanager/view/">-->
          <!--              <span>查看</span>-->
          <!--            </router-link>-->
          <!--                <el-button-->
          <!--                  size="mini"-->
          <!--                  type="text"-->
          <!--                  icon="el-icon-time"-->
          <!--                  @click="handlePath(scope.row)"-->
          <!--                  v-hasPermi="['system:dict:path']"-->
          <!--                >跟踪</el-button>-->
        </template>
      </el-table-column>
  </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!--修改对话框 -->
    <el-dialog :title="title" :visible.sync="isUpdateDialogOpen" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!--        <el-form-item label="字典名称" prop="dictName">-->
        <!--          <el-input v-model="form.dictName" placeholder="请输入字典名称" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="字典类型" prop="dictType">-->
        <!--          <el-input v-model="form.dictType" placeholder="请输入字典类型" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="状态" prop="status">-->
        <!--          <el-radio-group v-model="form.status">-->
        <!--            <el-radio-->
        <!--              v-for="dict in dict.type.sys_normal_disable"-->
        <!--              :key="dict.value"-->
        <!--              :label="dict.value"-->
        <!--            >{{dict.label}}</el-radio>-->
        <!--          </el-radio-group>-->
        <!--        </el-form-item>-->

        <el-form-item label="修改值" prop="status">
          <el-input v-model="form.dictName" placeholder="请输入修改后的值" />
        </el-form-item>
        <!--        <el-form-item label="备注" prop="remark">-->
        <!--          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>-->
        <!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!--跟踪对话框-->
    <el-dialog :title="title" :visible.sync="isPathDialogOpen" width="500px" append-to-body>
      <div class="timeline">
        <el-timeline>
          <el-timeline-item
            v-for="(item, index) in timelineData"
            :key="index"
            :timestamp="item.timestamp"
            :placement="index % 2 === 0 ? 'left' : 'right'"
            color="blue">
            {{ item.content }}
          </el-timeline-item>
        </el-timeline>
      </div>
    </el-dialog>
  </div>


</template>

<script>
import { listMenu, getMenu, delMenu, addMenu, updateMenu } from "@/api/system/menu";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import IconSelect from "@/components/IconSelect";

export default {
  name: "viewBaseDta",
  dicts: ['sys_show_hide', 'sys_normal_disable'],
  components: { Treeselect, IconSelect },
  data() {
    return {
      // 遮罩层
      loading: true,
      activeName :'first',
      // 显示搜索条件
      showSearch: true,
      // 菜单表格树数据
      menuList: [],
      //表格
      dataList:[
        {
          id:'1',
          dataName:'数据1',
          standardName: 'ISO 7055',
          status:'审核通过',
          remark:'1',
          createTime:'1001',
        },
        {
          id:'2',
          dataName:'数据2',
          standardName: 'ISO 19345',
          status:'审核通过',
          remark:'2',
          createTime:'1001',
        },
        {
          id:'3',
          dataName:'数据3',
          standardName: 'ISO 16708:2016',
          status:'审核通过',
          remark:'3',
          createTime:'1001',
        },
        {
          id:'4',
          dataName:'数据4',
          standardName: 'ISO 20729:2017',
          status:'审核失败',
          remark:'4',
          createTime:'1001',
        },
        {
          id:'5',
          dataName:'数据5',
          standardName: 'ISO 20676:2018',
          status:'待审核',
          remark:'5',
          createTime:'1001',
        },
      ],
      dataList3:[
        {
          id:'1',
          dataName:'ISO 7055',
          remark:'1',
          createTime:'1001',
        },
        {
          id:'2',
          dataName:'ISO 19345',
          remark:'2',
          createTime:'1001',
        },
        {
          id:'3',
          dataName:'ISO 16708:2016',
          remark:'3',
          createTime:'1001',
        },
        {
          id:'4',
          dataName:'ISO 20729:2017',
          remark:'4',
          createTime:'1001',
        },
        {
          id:'5',
          dataName:'ISO 20676:2018',
          remark:'5',
          createTime:'1001',
        },
      ],
      dataList2:[
        {
          dictName: 'A标准制定过程影响力',
          value:'90',
          children:[
            {
              dictName: 'A1参与主体影响力',
              value:'80',
              children:[
                {
                  dictName: 'A11参与国家影响力',
                  value:'83',
                },
                {
                  dictName: 'A12参与企业/组织影响力(加分项)',
                  value:'85',
                },
                {
                  dictName: 'A13 起草人员（时间节点有待确定）',
                  value:'86',
                },
              ]
            },
          ]
        },
        {
          dictName: 'B标准实施过程影响力',
          value:'87',
          children:[
            {
              dictName: 'B1标准应用',
              value:'89',

              children:[
                {
                  dictName: 'B11 标准转化',
                  value:'91',

                },
                {
                  dictName: 'B12其他标准引用',
                  value:'93',

                },
                {
                  dictName: 'B13被法律法规引用',
                  value:'87',

                },
                {
                  dictName: 'B14 其他工程应用（加分项）',
                  value:'83',

                },
              ]
            },
            {
              dictName: 'B2市场推广',
              value:'93',

              children:[
                {
                  dictName: 'B21标准传播',
                  value:'91',

                },
                {
                  dictName: 'B22认证认可',
                  value:'89',

                },
                {
                  dictName: 'B23标准关注度',
                  value:'93',

                },
                {
                  dictName: 'B24 标准衍生材料传播（加分项）',
                  value:'95',
                },
              ]
            },
            {
              dictName: 'B3标准先进性',
              value:'87',

              children:[
                {
                  dictName: 'B31标准引领性',
                  value:'91',

                },
                {
                  dictName: 'B32标准创新性',
                  value:'93',
                },
                {
                  dictName: 'B33标准获奖（加分项）',
                  value:'95',
                },
              ]
            },
            {
              dictName: 'B4社会效益',
              value:'83',
              children:[
                {
                  dictName: 'B41 社会关注度',
                  value:'87',

                },
                {
                  dictName: 'B42可持续发展支撑度',
                  value:'93',

                },
                {
                  dictName: 'B43对外贸易应用（国际贸易影响）',
                  value:'92',

                },
                {
                  dictName: 'B44产业扩散广度',
                  value:'90',

                },
              ]
            },
          ]
        },
      ],
      // 菜单树选项
      menuOptions: [],
      // 弹出层标题
      title: "",
      // 新增对话框显示状态，默认为false
      isAddDialogOpen: false,
      // 修改对话框显示状态，默认为false
      isUpdateDialogOpen: false,
      // 查看对话框显示状态，默认为false
      isViewDialogOpen: false,
      // 跟踪对话框显示状态，默认为false
      isPathDialogOpen: false,
      // 新增对话框显示状态，默认为false
      isAddDialogOpen2: false,
      // 修改对话框显示状态，默认为false
      isUpdateDialogOpen2: false,
      // 查看对话框显示状态，默认为false
      isViewDialogOpen2: false,
      // 跟踪对话框显示状态，默认为false
      isPathDialogOpen2: false,
      // 是否展开，默认全部折叠
      isExpandAll: false,
      // 重新渲染表格状态
      refreshTable: true,
      //时间线数据
      timelineData: [
        { timestamp: '2024-02-20', content: '创建 by 用户1' },
        { timestamp: '2024-02-23', content: '修改 by 用户2' },
        { timestamp: '2024-03-05', content: '修改 by 用户3' },
        { timestamp: '2024-03-10', content: '修改 by 用户4' },
        { timestamp: '2024-03-20', content: '修改 by 用户5' },
        { timestamp: '2024-03-30', content: '修改 by 管理员' },
        { timestamp: '2024-04-10', content: '修改 by 管理员' },
        // ...更多数据
      ],
      timelineData2: [
        { timestamp: '2015-09-01', content: '增加数据1 by 用户1' },
        { timestamp: '2015-09-02', content: '修改数据2 by 用户2' },
        { timestamp: '2015-09-03', content: '修改数据1 by 用户3' },
        { timestamp: '2015-09-04', content: '修改数据2 by 用户4' },
        { timestamp: '2015-09-05', content: '修改数据3 by 用户5' },
        { timestamp: '2015-09-06', content: '删除数据3 by 用户6' },
      ],
      // 查询参数
      queryParams: {
        menuName: undefined,
        visible: undefined
      },
      // 表单参数
      form: {},
      //搜索的状态下拉框
      statusOptions : [
        {
          value: '审核通过',
          label: '审核通过',
        },
        {
          value: '审核失败',
          label: '审核失败',
        },
        {
          value: '待审核',
          label: '待审核',
        },
      ],
      //选择数据类型的下拉框
      typeOptions : [
        {
          value: '标准文件',
          label: '标准文件',
        },
        {
          value: '补充文件',
          label: '补充文件',
        },
      ],
      // 表单校验
      rules: {
        menuName: [
          { required: true, message: "菜单名称不能为空", trigger: "blur" }
        ],
        orderNum: [
          { required: true, message: "菜单顺序不能为空", trigger: "blur" }
        ],
        path: [
          { required: true, message: "路由地址不能为空", trigger: "blur" }
        ]
      },

      // 用户导入参数
      upload: {
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        // headers: {Authorization: "Bearer " + getToken()},
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/business/talkrecord/importAllRecords"//文件上传路径
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //标签页切换
    // handleTabClick(tab) {
    //   console.log('Tab clicked:', tab);
    // },
    // 选择图标
    selected(name) {
      this.form.icon = name;
    },
    /** 获取状态 */
    getStatusTagType(status) {
      if (status === '审核通过') {
        return 'success';
      } else if (status === '审核失败') {
        return 'danger';
      } else if (status === '待审核') {
        return 'warning';
      } else {
        return 'info';
      }
    },
    /** 查询菜单列表 */
    getList() {
      this.loading = true;
      listMenu(this.queryParams).then(response => {
        this.menuList = this.handleTree(response.data, "menuId");
        this.loading = false;
      });
    },
    /** 转换菜单数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.menuId,
        label: node.menuName,
        children: node.children
      };
    },
    /** 查询菜单下拉树结构 */
    getTreeselect() {
      listMenu().then(response => {
        this.menuOptions = [];
        const menu = { menuId: 0, menuName: '主类目', children: [] };
        menu.children = this.handleTree(response.data, "menuId");
        this.menuOptions.push(menu);
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        menuId: undefined,
        parentId: 0,
        menuName: undefined,
        icon: undefined,
        menuType: "M",
        orderNum: undefined,
        isFrame: "1",
        isCache: "0",
        visible: "0",
        status: "0"
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 新增按钮操作 */
    handleAdd(row) {
      this.reset();
      this.getTreeselect();
      if (row != null && row.menuId) {
        this.form.parentId = row.menuId;
      } else {
        this.form.parentId = 0;
      }
      this.isAddDialogOpen = true;
      this.title = "添加菜单";
    },
    /** 查看操作 */
    handleView(row){
      // this.reset();
      // this.getTreeselect();
      // getMenu(row.id).then(response => {
      //   this.form = response.data;
      //   this.isViewDialogOpen = true;
      //   this.title = "";
      // });
      this.$router.push('/datamanager/viewBaseData');
    },
    /** 跟踪操作 */
    handlePath(row){
      // this.reset();
      // this.getTreeselect();
      // getMenu(row.id).then(response => {
      //   this.form = response.data;
        this.isPathDialogOpen = true;
        this.title = "";
      // });
    },
    /** 新增按钮操作 */
    handleAdd2(row) {
      this.reset();
      this.getTreeselect();
      if (row != null && row.menuId) {
        this.form.parentId = row.menuId;
      } else {
        this.form.parentId = 0;
      }
      this.isAddDialogOpen2 = true;
      this.title = "添加菜单";
    },
    /** 查看操作 */
    handleView2(row){
      // this.reset();
      // this.getTreeselect();
      // getMenu(row.id).then(response => {
      //   this.form = response.data;
      //   this.isViewDialogOpen2 = true;
      //   this.title = "";
      // });
      this.$router.push('/datamanager/viewBaseStandard');
      // this.$router.push('/');
    },
    /** 跟踪操作 */
    handlePath2(row){
      this.reset();
      this.getTreeselect();
      getMenu(row.id).then(response => {
        this.form = response.data;
        this.isPathDialogOpen2 = true;
        this.title = "";
      });
    },
    /** 展开/折叠操作 */
    toggleExpandAll() {
      this.refreshTable = false;
      this.isExpandAll = !this.isExpandAll;
      this.$nextTick(() => {
        this.refreshTable = true;
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // this.reset();
      // this.getTreeselect();
      // getMenu(row.dictName).then(response => {
      //   this.form = response.data;
        this.isUpdateDialogOpen = true;
        this.title = "修改菜单";
      // });
    },
    /** 修改按钮操作 */
    handleUpdate2(row) {
      this.reset();
      this.getTreeselect();
      getMenu(row.id).then(response => {
        this.form = response.data;
        this.isUpdateDialogOpen2 = true;
        this.title = "修改菜单";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.menuId != undefined) {
            updateMenu(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMenu(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal.confirm('是否确认删除名称为"' + row.menuName + '"的数据项？').then(function() {
        return delMenu(row.menuId);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },

  },

};
</script>

<style scoped>

</style>
